//index.js

//获取应用实例
const app = getApp()
var data = [
  { id: 5, type: '1', title: '中央政治局同志向党中央和习近平总书记述职', image: ['/public/images/3.jpg'], form: '湖北卫视', commentNum: '1' },
  { id: 6, type: '2', title: '中央政治局同志向党中央和习近平总书记述职', image: ['/public/images/3.jpg', '/public/images/2.jpg', '/public/images/3.jpg'], form: '凤凰卫视', commentNum: '1' },
  { id: 7, type: '2', title: '中央政治局同志向党中央和习近平总书记述职', image: [], form: "陕西卫视", commentNum: '1' },
  { id: 8, type: '3', title: '中央政治局同志向党中央和习近平总书记述职', image: ['/public/images/3.jpg'], form: "陕西卫视", commentNum: '1' },
  { id: 9, type: '1', title: '中央政治局同志向党中央和习近平总书记述职', image: ['/public/images/3.jpg'], form: "陕西卫视", commentNum: '1' },
  { id: 10, type: '1', title: '中央政治局同志向党中央和习近平总书记述职', image: ['/public/images/3.jpg'], form: "陕西卫视", commentNum: '1' },
]
var data1 = [
  { id: 5, title: '中央政治局同志向党中央和习近平总书记述职1', image: ['/public/images/3.jpg'], palyTime: "3:15", authorImg: "/public/images/3.jpg", author: '凤凰', playNum: 20, commentNum: 100 },
  { id: 5, title: '中央政治局同志向党中央和习近平总书记述职1', image: ['/public/images/3.jpg'], palyTime: "3:15", authorImg: "/public/images/3.jpg", author: '凤凰', playNum: 20, commentNum: 100 }, { id: 5, title: '中央政治局同志向党中央和习近平总书记述职1', image: ['/public/images/3.jpg'], palyTime: "3:15", authorImg: "/public/images/3.jpg", author: '凤凰', playNum: 20, commentNum: 100 }, { id: 5, title: '中央政治局同志向党中央和习近平总书记述职1', image: ['/public/images/3.jpg'], palyTime: "3:15", authorImg: "/public/images/3.jpg", author: '凤凰', playNum: 20, commentNum: 100 }
]
Page({
  data: {
    menuList: [{ titleName: '推荐', titleType: '1' }, { titleName: '视频', titleType: '2' }, { titleName: '热点', titleType: '1' }, { titleName: '本地', titleType: '1' }, { titleName: '社会', titleType: '1' }, { titleName: '娱乐', titleType: '1' }, { titleName: '科技', titleType: '1' }, { titleName: '汽车', titleType: '1' }, { titleName: '体育', titleType: '1' }, { titleName: '财经', titleType: '1' }, { titleName: '军事', titleType: '1' }],
    menuList2: [{ titleName: '推荐', titleType: '1' }, { titleName: '视频', titleType: '2' }, { titleName: '热点', titleType: '1' }, { titleName: '本地', titleType: '1' }, { titleName: '社会', titleType: '1' }, { titleName: '娱乐', titleType: '1' }, { titleName: '科技', titleType: '1' }, { titleName: '汽车', titleType: '1' }, { titleName: '体育', titleType: '1' }, { titleName: '财经', titleType: '1' }, { titleName: '军事', titleType: '1' }],
    newList: [
    ],
    newType: 1,
    page_height: 0,
    menuStatic: "menu_static",
    navHover_id: 0,
    duration: 500,
    menuhide:0
  },
  intervalChange: function (e) {
    console.log(e)
    this.loading()
    var that = this, newtype = that.data.newType, l = []
    console.log(newtype)
    if (newtype == 2) { var list = data1 } else { var list = data }
    this.setData({
      navHover_id: e.detail.current,
      newList: list
    })
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function (e) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        if (that.data.newType == 2) { var list = data1 } else { var list = data }
        that.setData({
          page_height: res.windowHeight,
          navHover_id: 0,
          newList:list
        })
      },
    })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true,
        navHover_id: e.id,
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function (e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  navTab: function (e) {
    var that = this,newtype = e.currentTarget.dataset.newtype
    if (that.data.newType == 2) { var list = data1 } else { var list = data }
    this.setData({
      newList: list,
      newType: newtype,
      navHover_id: e.currentTarget.id,
      duration: 0
    })
  },
  scrollBottom: function (e) {
    this.loading()
    var that = this, currun = that.data.navHover_id;
    if (e.currentTarget.dataset.newtype == 2) { var list = data1 } else { var list = data }
    var l = that.data.newList
    for (var i = 0; i < list.length; i++) {
      l.push(list[i])
    }
    that.setData({
      newList: l
    })
  },
  loading:function(){
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 2000
    })
  },
  viewHide:function(){
    var val = this.data.viewhide == 1?0:1
    this.setData({
      viewhide:val
    })
  },
  menuAdd:function(e){
    var that = this, l = that.data.menuList, node = that.data.menuList2, data = { titleName: e.target.dataset.name, titleType: e.target.dataset.type}
    var a = node.splice(e.target.id,1)
    l.push(data)
    this.setData({
      menuList: l,
      menuList2: node,
    })
  }
})
